package com.th;

/**
 * @version 1.0
 * @Author: 许啸林
 * @Date: 2021/8/30 15:01
 * 在main 线程中启动两个子线程
 */
public class Thread03 {
    public static void main(String[] args) {
        Th1 th1 = new Th1();
        Th2 th2 = new Th2();
        Thread thread1 = new Thread(th1);
        Thread thread2 = new Thread(th2);
        thread1.start();
        thread2.start();

    }
}

class Th1 implements  Runnable {
    @Override
    public void run() {
        for(int i=1; i<= 10; i++ ) {
            System.out.println(Thread.currentThread().getName() + " 线程执行" + i + '次' );
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class Th2 implements  Runnable {
    @Override
    public void run() {
        for(int i=1; i<= 10; i++) {
            System.out.println(Thread.currentThread().getName() + " 线程执行" + i + '次' );
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
